<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script type="text/javascript" src="../../res/js/jquery-3.1.1.min.js"></script>
    <script  type="text/javascript"   src="../../res/layui/layui.js"></script>
    <script type="text/javascript"  src="../../res/js/login_common.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">

        <div class="layui-inline">
            <input class="layui-input"id="schemeName" name="schemeName"  autocomplete="off" placeholder="请输入方案名称">
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="stime" name="stime" placeholder="请输入开始日期" >
        </div>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="etime" name="etime"  placeholder="请输入结束日期" >
        </div>
        <button class="layui-btn" data-type="reload" lay-event="findByKey" id="findByKey">搜索</button>

        <button class="layui-btn layui-btn-sm" lay-event="daochu">批量导出</button>
        <!--教练-->
        {{# if(hasPrivilege("SCHEME-COACH")){ }}
        {{# if(loginObj.manager.filld == d.coachId || loginObj.manager.manCardid == "superman"){ }}
        <button class="layui-btn layui-btn-sm" lay-event="add">增加方案</button>

        {{# } else{}}


        {{# } }}
        {{# } }}
</script>

<script type="text/html" id="barDemo">


    <!--教练-->
    {{# if(hasPrivilege("SCHEME-COACH")){ }}
    {{# if(loginObj.manager.filld == d.coachId || loginObj.manager.manCardid == "superman"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="fankui">反馈</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="expert">申请专家咨询</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    {{# } else{}}
    <a class="layui-btn layui-btn-xs" lay-event="edit" disabled="disabled">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="fankui" disabled="disabled">反馈</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="expert" disabled="disabled">申请专家咨询</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" disabled="disabled">删除</a>
    {{# } }}
    {{# } }}

    <!--领导-->
    {{# if(hasPrivilege("SHENHE")){ }}
    {{# if(d.auditState=="申请" || loginObj.manager.userId == "superman"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="shenhe">审核</a>
    {{# } else{}}
    <a class="layui-btn layui-btn-xs layui-btn-disabled " lay-event="shenhe">审核</a>
    {{# } }}
    {{# } }}


    <a class="layui-btn layui-btn-xs" lay-event="chakan">查看</a>
   <!--专家-->
    {{# if(hasPrivilege("HUIFU")){ }}
    {{# if(d.auditState=="领导已同意" || loginObj.manager.manCardid == "superman"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="huifu">回复</a>
    {{# } else{}}
    <a class="layui-btn layui-btn-xs layui-btn-disabled " lay-event="huifu" >回复</a>
    {{# } }}
    {{# } }}
</script>

<script type="text/html" id="file">
    <a class="layui-btn layui-btn-xs" lay-event="fileload"><i class="layui-icon"></i>上传文件</a>

</script>



<script>
    var table2 = null ;
    layui.use('table', function() {
        var table = layui.table;

        table2 = table.render({
            elem: '#test'
            , url: '../../atsScheme/findAll?schemeType=心理训练方案'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                , layEvent: 'LAYTABLE_TIPS'
                , icon: 'layui-icon-tips'
            }]
            , title: '用户数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'schemeId', title: '方案Id', width: 80, fixed: 'left', unresize: true, sort: true}
                , {field: 'schemeName', title: '方案名称', width: 120, edit: 'text'}
                , {field: 'year', title: '方案年度', width: 150}
                , {field: 'month', title: '方案月份', width: 150}
                , {field: 'schemeType', title: '方案类型', width: 100}
                , {field: 'file1', title: '附件1', width: 100, toolbar: '#asrc'}
                , {field: 'file2', title: '附件2', width: 100, toolbar: '#bsrc'}
                , {field: 'file3', title: '附件3', width: 100, toolbar: '#csrc'}
                , {field: 'coachName', title: '教练姓名', width: 100, sort: true}
                , {field: 'resultTime', title: '反馈时间', width: 120}
                , {field: 'resultEffect', title: '实施效果', width: 120}
                , {field: 'resultFile', title: '实施附件', width: 120}
                , {field: 'resultExp', title: '实施情况', width: 120}
                , {field: 'sort', title: '排序', width: 120}
                , {field: 'creater', title: '创建者', width: 120}
                , {field: 'creatTime', title: '创建时间', width: 120}
                , {field: 'isva', title: '是否有效', width: 120}
                , {field: 'remark', title: '备注', width: 120}
                ,{field:'applyForTime' ,  title:'申请时间', width:150}
                ,{field:'applyForExp' ,  title:'申请理由', width:150}
                ,{field:'auditState' ,  title:'审核状态', width:150}
                ,{field:'results' ,  title:'专家咨询结果', width:150}
                ,{field:'athleteName' ,  title:'运动员姓名', width:150}
                , {fixed: 'caozuo', title: '操作', toolbar: '#barDemo', width: 350, fixed: 'right'}
            ]]
          /*  ,done: function () {
                $("[data-field='auditState']").css('display','none');
            }*/
            , page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选');
                    break;

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
                case 'add':
                    layer.open({
                        type: 2,
                        title: '上传文件',
                        closeBtn: 1, //不显示关闭按钮
                        shade: [0],//背景色透明度
                        area: ['80%', '90%'],
                        anim: 2,//动画效果
                        content: ['scwj.html', 'no'],
                        end: function () {
                        }
                    });
                    break;
                case 'daochu':
                    var data = checkStatus.data;
                    $.each(data, function(index, item) {

                        setTimeout(function(){
                            var url="../../ExportWord/expertWord?schemeId="+item.schemeId;
                            alert(index);
                            window.open(url);
                        },1000)
                    });

                    break;
                case  'findByKey':
                    var schemeName=$("#schemeName").val();
                    var stime=$("#stime").val();
                    var etime=$("#etime").val();
                    table2.reload({
                        where: {
                            schemeName: $("#schemeName").val(),
                            stime: $("#stime").val(),
                            etime: $("#etime").val(),
                        },
                        page: {
                            curr: 1
                        }
                    });
                    rederTime();
                    //显示搜索的关键字
                    $("#schemeName").val(schemeName);
                    $("#stime").val(stime);
                    $("#etime").val(etime);
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('确认删除', function (index) {
                    var url = "../../atsScheme/updateId";
                    var datas = {schemeId: data.schemeId};

                    $.post(url, datas, function (objs) {
                        if (objs.num == 1) {
                            obj.del();
                            layer.close(index);
                            layer.msg('删除成功');
                        } else {
                            layer.msg('删除失败');
                        }
                    }, "json");


                });

            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2,
                    title: '修改',
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],//背景色透明度
                    area: ['80%', '90%'],
                    anim: 2,//动画效果
                    content: ['scwj.html?schemeId=' + data.schemeId],
                    end: function () {
                    }
                });
            } else if (obj.event === 'expert') {

                layer.open({
                    type: 2,
                    title: '申请专家咨询',
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],//背景色透明度
                    area: ['80%', '80%'],
                    anim: 2,//动画效果
                    content: ['expert.html?schemeId=' + data.schemeId],
                    end: function () {

                    }
                });

            } else if (obj.event === "chakan") {
                layer.open({
                    type: 2,
                    title: '查看详细信息',
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],//背景色透明度
                    area: ['80%', '80%'],
                    anim: 2,//动画效果
                    content: ['chakan.html?schemeId=' + data.schemeId],
                    end: function () {

                    }
                });
            } else if (obj.event === "fankui") {
                layer.open({
                    type: 2,
                    title: '反馈',
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],//背景色透明度
                    area: ['80%', '80%'],
                    anim: 2,//动画效果
                    content: ['fankui.html?schemeId=' + data.schemeId],
                    end: function () {

                    }
                });

            }else if(obj.event === "shenhe"){
                layer.open({
                    type: 2,
                    title: '审核',
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],//背景色透明度
                    area: ['80%', '80%'],
                    anim: 2,//动画效果
                    content: ['shenhe.html?schemeId=' + data.schemeId, 'no'],
                    end: function () {

                    }
                });
            }else if(obj.event === "huifu"){
                layer.open({
                    type: 2,
                    title: '回复',
                    closeBtn: 1, //不显示关闭按钮
                    shade: [0],//背景色透明度
                    area: ['80%', '80%'],
                    anim: 2,//动画效果
                    content: ['huifu.html?schemeId=' + data.schemeId, 'no'],
                    end: function () {

                    }
                });
            }
        });
        //刷新时间
        layui.use('laydate', function () {
            laydate = layui.laydate;
            //开始时间、结束时间
            laydate.render({
                elem: '#stime',
                trigger: 'click'
            });

            laydate.render({
                elem: '#etime',
                trigger: 'click'
            });
        });

        /**
         * 刷新时间控件
         */
        function rederTime() {
            laydate.render({
                elem: '#stime',
                trigger: 'click'
            });

            laydate.render({
                elem: '#etime',
                trigger: 'click'
            });
        }
    });
</script>
<script type="text/html" id="asrc">

    {{# if(d.file1!=null){ }}
    <a href="../../../hbatsams{{d.file1}}" id="lhc38" target="_blank" onclick = dianji("{{d.schemeId}}")>下载附件1</a>
    {{# } else{}}

    {{# } }}
</script>
<script type="text/html" id="bsrc">

    {{# if(d.file2!=null){ }}
    <a href="../../../hbatsams{{d.file2}}" value="{{d.schemeId}}" target="_blank" onclick = dianji2("{{d.schemeId}}")>下载附件2</a>
    {{# } else{}}

    {{# } }}
</script>
<script type="text/html" id="csrc">

    {{# if(d.file3!=null){ }}
    <a href="../../../hbatsams{{d.file3}}" value="{{d.schemeId}}" target="_blank" onclick = dianji3("{{d.schemeId}}")>下载附件3</a>
    {{# } else{}}

    {{# } }}
</script>
<script>
    var dianji = function(obj){
        var url = "../../atsScheme/updateisRead";
        var data = {schemeId: obj, num: 1};
        $.post(url, data, function (objs) {
            if (objs == 1) {
                layer.msg('下载成功');
            } else {
                layer.msg('下载成功');
            }
        });
    }
    var dianji2 = function(obj){
        var url = "../../atsScheme/updateisRead";
        alert(obj.schemeId);
        var data = {schemeId: obj, num: 2};
        $.post(url, data, function (objs) {
            if (objs == 1) {
                layer.msg('下载成功');
            } else {
                layer.msg('下载成功');
            }
        });
    }
    var dianji3 = function(obj){
        var url = "../../atsScheme/updateisRead";
        var data = {schemeId: obj, num: 3};
        $.post(url, data, function (objs) {
            if (objs == 1) {
                layer.msg('下载成功');
            } else {
                layer.msg('下载成功');
            }
        });
    }
</script>
</body>
</html>